package com.dqhl.business.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dqhl.business.R;
import com.dqhl.business.modle.GoodsType;
import com.dqhl.business.util.Dlog;
import com.dqhl.business.util.ViewHolder;

import java.util.List;

/**
 * Created by guanluocang on 2016/11/4.
 */
public class TypeManagerAdapter extends BaseAdapter {

    private Context context;
    private List<GoodsType> goodsTypeList;
    private LayoutInflater inflater;

    public TypeManagerAdapter(Context context, List<GoodsType> goodsTypeList) {
        this.goodsTypeList = goodsTypeList;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return goodsTypeList.size();
    }

    @Override
    public Object getItem(int i) {
        return goodsTypeList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    public void remove(int position) {
        goodsTypeList.remove(position);
        this.notifyDataSetChanged();
    }

    public void insert(GoodsType goodsType, int position) {
        goodsTypeList.add(position, goodsType);
        this.notifyDataSetChanged();
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = inflater.inflate(R.layout.item_lv_type_manager, viewGroup, false);

        }
        TextView tv_goodsTypeName = ViewHolder.get(view, R.id.tv_goodsTypeName);
        TextView tv_typeStatus = ViewHolder.get(view, R.id.tv_typeStatus);
        TextView tv_goodsNum = ViewHolder.get(view, R.id.tv_goodsNum);

        GoodsType goodsType = goodsTypeList.get(i);

        tv_goodsTypeName.setText(goodsType.getName());
        tv_goodsNum.setText(goodsType.getCount());

        String auditing = goodsType.getAuditing(); //审核（1代表待审核，2代表审核通过，3代表审核未通过）
        if ("1".equals(auditing)) {
            tv_typeStatus.setText("(审核中)");
        } else if ("2".equals(auditing)) {
            tv_typeStatus.setText("(审核通过)");
        } else if ("3".equals(auditing)) {
            tv_typeStatus.setText("(审核未通过)");
        }

        return view;
    }

    private class OnMenuClickListenser implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            int id = v.getId();
            if (id == R.id.tv_top) {
                Dlog.e("置顶");
            } else if (id == R.id.tv_move_up) {
                Dlog.e("上移");
            } else if (id == R.id.tv_move_down) {
                Dlog.e("下移");
            }
        }
    }
}
